package top.suven.base.http.admin.sec.dao;

import org.apache.ibatis.annotations.*;
import top.suven.base.core.mybatis.crud.CommonCrudMapper;
import top.suven.base.http.admin.sec.model.RoleMenu;

import java.util.List;

/**
 * @Title: RoleMenuService.java
 * @Description: 角色菜单权限的数据交互类
 * @author lixiangling
 * @date   2018/08/13 16:59:19
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
public interface RoleMenuDao extends CommonCrudMapper<RoleMenu> {
    @Select("<script> " +
            "select a.*,b.menu_name,b.menu_uri,b.menu_type,b.parent_menu_code from  sec_role_menu a,sec_menu b where a.menu_code=b.menu_code "+
            "and a.status='1' and a.enable_status='1' and b.status='1' and b.enable_status='1' and a.role_code in " +
            "<foreach item='item' index='index' collection='roleCodeList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    @Results(
            id="roleMenu",
            value = {
                    @Result(column = "role_menu_id" , property = "roleMenuId"),
                    @Result(column = "role_code" , property = "roleCode"),
                    @Result(column = "menu_code" , property = "menuCode"),
                    @Result(column = "menu_name" , property = "menuName"),
                    @Result(column = "menu_uri" , property = "menuUri"),
                    @Result(column = "menu_type" , property = "menuType"),
                    @Result(column = "parent_menu_code" , property = "parentMenuCode"),
                    @Result(column = "status" , property = "status"),
                    @Result(column = "reorder" , property = "reorder"),
                    @Result(column = "remark" , property = "remark"),
                    @Result(column = "enable_status" , property = "enableStatus")
            }
    )
    List<RoleMenu> getRoleMenuByRoleCodeList(@Param("roleCodeList") List<String> roleCodeList);
    /**
     * @Title: 删除角色菜单权限信息
     * @Description:id @{Link Long[]}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 16:59:19
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Update("<script> " +
            "UPDATE sec_role_menu set status='0'"+
            "WHERE role_menu_id IN " +
            "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    void del(@Param("idList") List<Long> idList);
    /**
     * @Title: 禁用角色菜单权限信息
     * @Description:id @{Link Long}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 16:59:19
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
     @Update("<script> " +
             "UPDATE sec_role_menu  " +
             "SET role_menu_id = #{enableStatus}  " +
             "WHERE user_id IN " +
             "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
             "#{item} " +
             "</foreach> " +
             "</script>")
     void updateEnableStatus(@Param("enableStatus") String enableStatus, @Param("idList") List<Long> idList);
}